fn main() {
    //if 
    let y = 0;
    if y==1 {
        println!("y = 1");
    } 

    // if-else
    if y == 1 {
        println!("y = 1");
    } else {
        println!("y != 1");
    }

    // if - else if - else 
    if y == 1 {
        println!("y = 1");
    } else if y ==2 {
        println!("y = 2");
    } else {
        println!("y = others");
    }


    // let 中使用if
    let condition = false;
    let x = if condition {
        5
    } else {
        6
        // "six" // error 需要的类型不匹配
    };
    println!("x = {}", x);
    
    // loop 循环
    let mut counter = 0;
    loop {
        println!("in loop {}", counter);
        if counter == 10 {
            break;
        }

        //counter = counter + 1;
        counter += 1;
    }

    // 循环结果可以放在变量中，break 后面可以跟着返回值
    let result = loop {
        counter += 1;
        if counter == 20 {
            break counter * 2;
        }
    };
    println!("result = {}", result);


    // while 循环
    let mut i = 0;
    while i != 10 {
        i += 1;
    }
    println!("i = {}", i);

    // for 循环
    println!("########################");
    let arr:[u32; 5] = [1,2,3,4,5];
    //for ele in arr.iter() {
    for ele in &arr {
        println!("element = {}", ele);
    }
    

    println!("Hello, world!");
}
